<?php

namespace App\Models\finance;

use App\Models\AdminModel;
use App\Models\AgentModel;
use App\Models\OrderModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model as BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @property int $id ID
 * @property int $agent_id 代理商ID
 * @property string $date 日期
 * @property int $order_id 入仓单ID
 * @property int $project_type 项目类型
 * @property decimal $weight 重量
 * @property decimal $amount 金额
 * @property decimal $registration_fee 登记费
 * @property decimal $parking_fee 停车费
 * @property decimal $tunnel_fee 隧道费
 * @property decimal $bridge_fee 桥梁费
 * @property decimal $scanning_fee 扫描费
 * @property decimal $other_fee 其他费用
 * @property decimal $total_amount 合计金额
 * @property string $remarks 备注
 * @property int $status 状态：1未付款 2部分付款 3已付款
 * @property decimal $pay_amount 已付金额
 * @property int $created_admin_id 创建人ID
 * @property string $created_at 创建时间
 * @property string $updated_at 更新时间
 * @property string $deleted_at 删除时间
 */
class PayableDeliveryRegistrationModel extends BaseModel
{
    use HasFactory, SoftDeletes;

    protected $table = 't_payble_delivery_registration';

    protected $primaryKey = 'id';

    public $timestamps = true;

    const CREATED_AT = 'created_at';
    
    const UPDATED_AT = null;

    protected $guarded = [];

    protected $hidden = [
        'deleted_at',
    ];

    // 项目类型
    const PROJECT_TYPE_PICKUP = 1;   // 提货
    const PROJECT_TYPE_DELIVERY = 2; // 送货
    const PROJECT_TYPE_OTHER = 3;    // 其他

    const PROJECT_TYPE_LIST = [
        self::PROJECT_TYPE_PICKUP => '提货',
        self::PROJECT_TYPE_DELIVERY => '送货',
        self::PROJECT_TYPE_OTHER => '其他',
    ];

    // 状态常量
    const STATUS_UNPAID = 1;      // 未付款
    const STATUS_PART_PAID = 2;   // 部分付款
    const STATUS_PAID = 3;        // 已付款

    const STATUS_LIST = [
        self::STATUS_UNPAID => '未付款',
        self::STATUS_PART_PAID => '部分付款',
        self::STATUS_PAID => '已付款',
    ];

    // 关联代理商
    public function agent(): BelongsTo 
    {
        return $this->belongsTo(AgentModel::class, 'agent_id');
    }

    // 关联入仓单
    public function order(): BelongsTo
    {
        return $this->belongsTo(OrderModel::class, 'order_id');
    }

    // 关联创建人
    public function createAdmin(): BelongsTo 
    {
        return $this->belongsTo(AdminModel::class, 'created_admin_id');
    }
} 